function hidethings() {
var query = window.location.search.substring(1);
var parms = query.split('&');
var qs = {};
for (var i=0; i<parms.length; i++) {
var pos = parms[i].indexOf('=');
if (pos > 0) {
var key = parms[i].substring(0,pos);
var val = parms[i].substring(pos+1);
qs[key] = val;
}
}
var success = qs['success'];
$("#right > div").each(function() { this.style.display='none'});
if(success=='true') {
$("#form_success")[0].style.display='inline'
} else if(success=='false') {
$("#form_error")[0].style.display='inline'
} else {
$("#form")[0].style.display='inline'
}
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
};

function validateForm(f) {
    var errors = 0;
    $(".required", f).map(function(){
         var parent = $(this).parent();
         if(parent) {
           var style = $('.failed', parent)[0].style
           if( !$(this).val() || $(this).is(".emailaddr") && !isValidEmailAddress($(this).val()) ) {
            style.display = 'inline';
            errors++;
          } else {
            style.display = 'none';
          }   
        }   
    });
    if(errors > 0){
        $('#form_advice').toggle(true);
        return false;
    }
    $('#form_advice').toggle(false);
    return true; 
}

window.onload=hidethings;
